package com.hzdl.controller;

import com.hzdl.bean.User;
import com.hzdl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;

/**
 * author:Administrator
 * date:2018\9\4 0004
 * description:
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public String login(String name, String psw, Model model, HttpSession session){
        User user = userService.login(name, psw);
        //System.out.println(user);
        if (user!=null){
            session.setAttribute("user",user);
            model.addAttribute("user",user);
            return "index";
        }
        model.addAttribute("msg","用户名或密码错误，请重新输入");
        return "login";
    }
    @RequestMapping("/toLogin")
    public String toLogin() {
        return "login";
    }

}
